function [ output_args ] = frprmn(p,n,ftol,iter,fret,func,dfunc)


ITMAX = 200;
EPS = 1.0e-10;
%#define FREEALL free_vector(xi,1,n);free_vector(h,1,n);free_vector(g,1,n);

%void frprmn(float p[], int n, float ftol, int *iter, float *fret,float (*func)(float []), void (*dfunc)(float [], float []))
%	void linmin(float p[], float xi[], int n, float *fret,
%		float (*func)(float []));
%	int j,its;
%	float gg,gam,fp,dgg;
%	float *g,*h,*xi;

%	g=vector(1,n);
%	h=vector(1,n);
%	xi=vector(1,n);
	%fp=(*func)(p);
    fp=feval(func,p);
	
    %(*dfunc)(p,xi);???
    
    g=-xi;
    h=g;
    xi=h;
    
    
	%for (j=1;j<=n;j++) {
	%	g[j] = -xi[j];
	%	xi[j]=h[j]=g[j];
	%}
	%for (its=1;its<=ITMAX;its++) {
    for its=1:ITMAX
		%*iter=its;
		linmin(p,xi,n,fret,func);
		if 2*abs(fret-fp) <= ftol*(abs(fret)+abs(fp)+EPS)
			%FREEALL
			return;
        end
		%}
		fp= fret;
		% (*dfunc)(p,xi); ???
        %gg=0;
        %dgg=gg;
		%dgg=gg=0.0;
		%for (j=1;j<=n;j++) {
		%	gg += g[j]*g[j];
		%	dgg += (xi[j]+g[j])*xi[j];
		%}
        gg = dot(g,g);
        dgg = dot((xi+g),xi);
        if gg == 0 % {
			%FREEALL
			return;
        end
		gam=dgg/gg;
		%for (j=1;j<=n;j++) {
        %for j=1:n
		%	g[j] = -xi[j];
		%	xi[j]=h[j]=g[j]+gam*h[j];
        %end
        g=-xi;
        h=g+gam*h;
        xi=h;
        
    end
	fprintf('Too many iterations in frprmn\n');



end

